#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define INF 0x3f3f3f3f
#define lc (o<<1)
#define rc (o<<1|1)
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=5e5+10;
int n,a[MAXN],nxt[MAXN],siz[MAXN],fa[MAXN],ans[MAXN];
db k;
inline bool cmp(int a,int b)
{
	return a>b;
}
struct Seg_T
{
	int minv[MAXN*3],addv[MAXN*3];
	void push_up(int o)
	{
		minv[o]=min(minv[lc],minv[rc]);
		return;
	}
	void push_down(int o)
	{
		if(addv[o])
		{
			minv[lc]+=addv[o];
			minv[rc]+=addv[o];
			addv[lc]+=addv[o];
			addv[rc]+=addv[o];
			addv[o]=0;
		}
		return;
	}
	void build(int o,int l,int r)
	{
		if(l==r)
		{
			minv[o]=l;
			return;
		}
		int mid=(l+r)>>1;
		build(lc,l,mid);
		build(rc,mid+1,r);
		push_up(o);
		return;
	}
	void update(int o,int l,int r,int yl,int yr,int k)
	{
		if(yl<=l&&r<=yr)
		{
			minv[o]+=k;
			addv[o]+=k;
			return;
		}
		push_down(o);
		int mid=(l+r)>>1;
		if(yl<=mid)update(lc,l,mid,yl,yr,k);
		if(yr>mid)update(rc,mid+1,r,yl,yr,k);
		push_up(o);
		return;
	}
	int query(int o,int l,int r,int k)
	{
		if(l==r)return l;
		push_down(o);
		int mid=(l+r)>>1;
		if(minv[rc]<k)return query(rc,mid+1,r,k);
		else return query(lc,l,mid,k);
	}
}T1;
int main()
{
	n=read();scanf("%lf",&k);
	for(int i=1;i<=n;++i)a[i]=read();
	sort(a+1,a+1+n,cmp);
	for(int i=n;i;--i)
	{
		nxt[i]=(a[i]==a[i+1])?nxt[i+1]:i;
		fa[i]=(int)floor(i/k);
		siz[fa[i]]+=(++siz[i]);
	}
	T1.build(1,0,n);
	for(int i=1;i<=n;++i)
	{
		if(fa[i]!=fa[i-1])T1.update(1,0,n,ans[fa[i]],n,siz[fa[i]]-1);
		ans[i]=nxt[T1.query(1,0,n,siz[i])+1];
		T1.update(1,0,n,ans[i],n,-siz[i]);
	}
	for(int i=1;i<=n;++i)printf("%d ",a[ans[i]]);
	puts("");
	return 0;
}
